package com.whfp.coky.ui.task.vm.fluor

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import com.whfp.coky.api.response.BaseResult
import com.whfp.coky.databinding.FragFluorProjCloudBinding
import com.whfp.coky.ui.base.BaseFragment
import com.whfp.coky.ui.base.model.RequestBean
import com.whfp.coky.ui.base.vm.RecycleVM
import com.whfp.coky.ui.task.model.FluorProjCloudBean

/**
 *
 *
 * created by coky on 2022/3/1
 */
class FluorProjCloudFragVM: RecycleVM<FragFluorProjCloudBinding, FluorProjCloudBean>() {

    var result = MutableLiveData<String>()

    override fun getStatusLayout() = vBinding.statusLayout

    override suspend fun httpBlock(page: Int) =
        httpUtil.doGetCloudBQ(pageIndex = page,
            bqName = (mRequest.value as ReqCurve).bqName)

    override fun observe(fragment: BaseFragment<*, *>, owner: LifecycleOwner) {
        super.observe(fragment, owner)
        result.observe(fragment, Observer {
            changeReq(it)
        })
    }

//    接口成功的判断
    override fun isHttpSuccess(httpResult: BaseResult<*>): Boolean {
        return httpResult.result == 0
    }

    override fun buildRequest() {
        mRequest.value = ReqCurve()
    }

    fun changeReq(bqName:String){
        if (bqName.isEmpty()){
            buildRequest()
        }else{
            mRequest.value = ReqCurve(bqName)
        }
    }


    fun doActivation(){
//        跳转扫码
    }

    fun doLocation(){

    }

    /**
     * 人员列表bean
     */
    class ReqCurve(var bqName: String = ""): RequestBean(){
        override fun toString(): String {
            return "bqName:${bqName}"
        }
    }
}